﻿package mortal.game.view.guildNew.WareHourse
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.events.*;
    import com.mui.manager.*;
    import extend.language.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guild.otherpanel.*;
    import mortal.game.view.guild.util.*;
    import mortal.mvc.core.*;

    public class GuildNewWareHCell extends GCellRenderer
    {
        protected var _nameT:GTextFiled;
        protected var _posT:GTextFiled;
        protected var _att:GTextFiled;
        protected var _list:CellsGridSprite;
        protected var _line:ScaleBitmap;
        protected var _levelT:GTextFiled;
        private var _starPanel1:StarPanel;
        private var _starPanel2:StarPanel;
        private var _starPanel3:StarPanel;

        public function GuildNewWareHCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._nameT = UIFactory.gTextField("", -1, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._posT = UIFactory.gTextField("", -19, 26, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._att = UIFactory.gTextField("10000", 98, 5, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._list = UIFactory.getUICompoment(CellsGridSprite);
            this._list.colNum = 4;
            this._list.vCellWid = 42;
            this._list.hCellWid = 100;
            this._list.genCellFun = this.genCell;
            this._list.genCells(3);
            this._list.x = 191;
            this._list.y = 4;
            this.addChild(this._list);
            this._line = UIFactory.bg(2, 48, 320, 1, this, ImagesConst.SplitLine);
            this._levelT = UIFactory.gTextField("56级", 63, 26, 30, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).right());
            this._starPanel1 = UIFactory.getUICompoment(StarPanel, 110, 22, this);
            this._starPanel1.mouseEnabled = true;
            this._starPanel1.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            this._starPanel2 = UIFactory.getUICompoment(StarPanel, 133, 22, this);
            this._starPanel2.mouseEnabled = true;
            this._starPanel2.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            this._starPanel3 = UIFactory.getUICompoment(StarPanel, 156, 22, this);
            this._starPanel3.mouseEnabled = true;
            this._starPanel3.setStarStyle(ImagesConst.GuildWarStarM, ImagesConst.GuildWarStarMGray, 25);
            var _loc_1:Number = 0.8;
            var _loc_2:* = _loc_1;
            this._starPanel1.scaleY = _loc_1;
            this._starPanel1.scaleX = _loc_2;
            var _loc_2:* = _loc_1;
            this._starPanel2.scaleY = _loc_1;
            this._starPanel2.scaleX = _loc_2;
            var _loc_2:* = _loc_1;
            this._starPanel3.scaleY = _loc_1;
            this._starPanel3.scaleX = _loc_2;
            return;
        }// end function

        private function genCell() : NumLevelBaseItem
        {
            var _loc_1:* = UIFactory.getUICompoment(NumLevelBaseItem);
            _loc_1.createDisposedChildren();
            _loc_1.setItemStyle();
            _loc_1.isDragAble = true;
            _loc_1.isDropAble = true;
            _loc_1.configEventListener(DragEvent.Event_Move_In, this.onMoveIn);
            _loc_1.configEventListener(DragEvent.Event_Throw_goods, this.onThrowGoods);
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._nameT = null;
            this._posT = null;
            this._att = null;
            this._list = null;
            this._line = null;
            this._levelT = null;
            if (this._starPanel1)
            {
                ToolTipsManager.unregister(this._starPanel1);
                this._starPanel1.dispose(param1);
                this._starPanel1 = null;
            }
            if (this._starPanel2)
            {
                ToolTipsManager.unregister(this._starPanel1);
                this._starPanel2.dispose(param1);
                this._starPanel2 = null;
            }
            if (this._starPanel3)
            {
                ToolTipsManager.unregister(this._starPanel1);
                this._starPanel3.dispose(param1);
                this._starPanel3 = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function onMoveIn(event:DragEvent) : void
        {
            var dropItem:BaseItem;
            var playerItem:SPlayerItem;
            var onYes:Function;
            var e:* = event;
            onYes = function (param1:int) : void
            {
                dropItem.itemData = new ItemData(playerItem.itemCode);
                dropItem.amount = param1;
                GuildResourceRecordUitl.instance.addItems(playerItem, param1, itemData.playerId, _list.cellArr.indexOf(dropItem));
                return;
            }// end function
            ;
            var dragItem:* = e.dragItem as BaseItem;
            dropItem = e.dropItem as BaseItem;
            if (dragItem.parent is GuildNewWHItemCell)
            {
                playerItem = ItemData(e.dragSouce).serverData;
                if (playerItem.itemAmount > 1)
                {
                    SelectNumPanel.instance.show();
                    SelectNumPanel.instance.setData(e.dragSouce as ItemData, Language.getString(70533), Language.getString(70534), onYes);
                    return;
                }
                this.onYes(playerItem.itemAmount);
            }
            return;
        }// end function

        private function onThrowGoods(event:DragEvent) : void
        {
            var dragItem:BaseItem;
            var itemInfo:ItemData;
            var onYes:Function;
            var e:* = event;
            onYes = function (param1:int) : void
            {
                if (itemInfo.itemAmount > param1)
                {
                    itemInfo.itemAmount = itemInfo.itemAmount - param1;
                    dragItem.itemData = itemInfo;
                }
                else
                {
                    dragItem.itemData = null;
                }
                GuildResourceRecordUitl.instance.delItems(itemInfo.itemCode, param1, itemData.playerId, _list.cellArr.indexOf(dragItem));
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildResourceSelectItemUpdata));
                return;
            }// end function
            ;
            dragItem = e.dragItem as BaseItem;
            itemInfo = e.dragSouce as ItemData;
            itemInfo.itemAmount = dragItem.amount;
            if (itemInfo.itemAmount > 1)
            {
                SelectNumPanel.instance.show();
                SelectNumPanel.instance.setData(itemInfo, Language.getString(70533), Language.getString(70534), onYes);
                return;
            }
            this.onYes(itemInfo.itemAmount);
            return;
        }// end function

        private function get itemData() : SGuildParticipationInfo
        {
            return data as SGuildParticipationInfo;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_5:NumLevelBaseItem = null;
            var _loc_6:SPlayerItem = null;
            super.data = param1 as SGuildParticipationInfo;
            this._nameT.text = this.itemData.name;
            this._levelT.text = this.itemData.level.toString() + Language.getString(71627);
            this._posT.text = GameDefConfig.instance.getItem("EGuildPostion", this.itemData.position).text;
            this._att.text = this.itemData.contributionWeek.toString();
            var _loc_2:int = 14;
            var _loc_3:* = DailyConfig.instance.getWeekTimeById(GameDefConfig.instance.getDailyViewConfigId(2));
            var _loc_4:* = DailyConfig.instance.getWeekTimeById(GameDefConfig.instance.getDailyViewConfigId(3));
            this._starPanel1.setStarNum(1, this.itemData.worldBossTimes / _loc_2);
            this._starPanel2.setStarNum(1, this.itemData.guildWarTimes / _loc_3);
            this._starPanel3.setStarNum(1, this.itemData.guildTaskTimes / _loc_4);
            ToolTipsManager.unregister(this._starPanel1);
            ToolTipsManager.unregister(this._starPanel2);
            ToolTipsManager.unregister(this._starPanel3);
            ToolTipsManager.register(this._starPanel1, null, Language.getStringByParam(70537, this.itemData.worldBossTimes, _loc_2));
            ToolTipsManager.register(this._starPanel2, null, Language.getStringByParam(70538, this.itemData.guildWarTimes, _loc_3));
            ToolTipsManager.register(this._starPanel3, null, Language.getStringByParam(70539, this.itemData.guildTaskTimes, _loc_4));
            var _loc_7:int = 0;
            while (_loc_7 < 3)
            {
                
                _loc_5 = this._list.cellArr[_loc_7];
                if (GuildResourceRecordUitl.instance.getPlayerItem(this.itemData.playerId, _loc_7))
                {
                    _loc_6 = new SPlayerItem();
                    ClassTypesUtil.copyClassValue(_loc_6, GuildResourceRecordUitl.instance.getPlayerItem(this.itemData.playerId, _loc_7));
                    _loc_5.itemData = new ItemData(_loc_6);
                }
                else
                {
                    _loc_5.itemData = null;
                }
                _loc_7++;
            }
            return;
        }// end function

    }
}
